Arduino之所以会火,是因为它的易用性.而它的易用性则来源与世界各地的程序员为它做好的易用的库.AVR的使用相对Arduino比较难,因为它要设置各种寄存器,提高AVR的使用性的方法就是把每一个功能模块都写成库,不管什么使用,都只要调用一两个函数就好了.
我会在此博客持续更新我自己的AVR库,方便大家的使用.
个人原创,转载请注明原文出处,并保留链接:
http://www.embbnux.com/2014/03/23/use_avr_like_arduino_lcd1602/
今天 公开的是1602LCD接口驱动:
头文件及使用介绍:
/****************************************************************** ========CopyRight of Embbnux Ji ======================================== ========Writer : Embbnux Ji ============================================ ========http://www.embbnux.com ========================================= ==========avr 1602_lcd驱动程序 ============================================ ===========ATmega16 16MHZ ========================================== *********************************************************************/ #ifndef DRIVER_1602_H_H_ #define DRIVER_1602_H_H_ # include <avr/io.h> #define LCD_DATA_PORT PORTC //定义LCD的D0-D7所在端口 #define LCD_DATA_POUT DDRC=0xFF //定义LCD数据端口为输出 #define LCD_DATA_PIN DDRC=0x00 //定义LCD数据端口为输入(在读LCD状态时用到) #define LCD_Control_PORT PORTB //定义LCD的EN RW RS所在端口 #define LCD_Control_OUT DDRB|=(1<<DDB5)|(1<<DDB6)|(1<<DDB7) #define LCD_Control_IN DDRB&=~((1<<DDB5)|(1<<DDB6)|(1<<DDB7)) #define LCD_EN_1 PORTB|=1<<PB5 #define LCD_EN_0 PORTB&=~(1<<PB5) //LCD读写控制引脚 #define LCD_RW_1 PORTB|=1<<PB6 #define LCD_RW_0 PORTB&=~(1<<PB6) //LCD指令或数据选择引脚 #define LCD_RS_1 PORTB|=1<<PB7 #define LCD_RS_0 PORTB&=~(1<<PB7) extern void LCD_init(void); extern void mcu_init(void); extern void LCD_en_write(void); extern void wait_LCD_Ready(void); extern void set_LCD_xy(unsigned char x, unsigned char y ); extern void LCD_write_onechar(unsigned char COMM,unsigned char DAT); extern void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *string); extern void LCD_close(); extern void LCD_clean(); extern void LCD_write_int(unsigned char X,unsigned char Y,unsigned int num); extern void int_to_char (unsigned int num,unsigned char * string); #endif
使用介绍:
LCD初始化:
LCD_init();
打印字符串从LCD的第一行的第一列开始:
unsigned char display[]= {" http://www.embbnux.com "}; LCD_write_string(0,0,display);
打印整型数到LCD:
unsigned int num = 200; LCD_write_int(0,1,num);
具体程序下载,请到我的github上下载: